package gao.xiaolei.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.boot.jackson.JsonComponent;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@JsonComponent
public class JsonLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {//用于配置jackson转换时间

    @Override
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String dateAsString = jsonParser.getText();
        return LocalDateTime.parse(dateAsString, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
